package com.zmx.patientend.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.gyf.immersionbar.ImmersionBar;
import com.itingchunyu.badgeview.BadgeTextView;
import com.wang.adapters.interfaceabstract.OnItemClickListener;
import com.zmx.patientend.MyApplication;
import com.zmx.patientend.R;
import com.zmx.patientend.adapter.BraceletDataAdapter;
import com.zmx.patientend.adapter.RecommendedDoctorAdapter;
import com.zmx.patientend.listener.InformUpdateListenerManager;
import com.zmx.patientend.listener.MessageUpdateListener;
import com.zmx.patientend.okhttp.OkHttp3ClientManager;
import com.zmx.patientend.pojo.BraceletData;
import com.zmx.patientend.pojo.Doctor;
import com.zmx.patientend.utils.AllUtil;
import com.zmx.patientend.view.activity.AllDoctorActivity;
import com.zmx.patientend.view.activity.BraceletDataActivity;
import com.zmx.patientend.view.activity.COVIDActivity;
import com.zmx.patientend.view.activity.CommunityActivity;
import com.zmx.patientend.view.activity.DiseaseSearchActivity;
import com.zmx.patientend.view.activity.DoctorDetailsActivity;
import com.zmx.patientend.view.activity.FamilyArchivesActivity;
import com.zmx.patientend.view.activity.FamousDoctorHallActivity;
import com.zmx.patientend.view.activity.HealthActivity;
import com.zmx.patientend.view.activity.HealthDetectionActivity;
import com.zmx.patientend.view.activity.IntelligentChatActivity;
import com.zmx.patientend.view.activity.LiveActivity;
import com.zmx.patientend.view.activity.LoginActivity;
import com.zmx.patientend.view.activity.MallMedicineActivity;
import com.zmx.patientend.view.activity.MedicinalFoodRecipesActivity;
import com.zmx.patientend.view.activity.MessageActivity;
import com.zmx.patientend.view.activity.PatientMessageDetailsActivity;
import com.zmx.patientend.view.activity.PatientsLocationActivity;
import com.zmx.patientend.view.activity.TCMKnowledgeActivity;
import com.zmx.patientend.view.activity.ThePreventionActivity;
import com.zmx.patientend.view.activity.UpdateIntelligentChatActivity;
import com.zmx.patientend.view.activity.XingGuanActivity;
import com.zmx.patientend.view.util.CustomTextSwitcher;
import com.zmx.patientend.view.util.MySharedPreferences;
import com.zmx.patientend.wangyiyun.permission.MPermission;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HomeFragment extends SimpleImmersionFragment {

    RelativeLayout laba,relative2, relative_f, relative3, relative4, relative5, relative6, relative8, relative7, relative9, relative10, zhibo, zhibo1, liLayout1, liLayout2, liLayout3, relative_a;

    private TextView more_doctor,l_More;
    private TextView message_button;

    private static BadgeTextView mBadgeView;

    private RecyclerView bracelet;
    private BraceletDataAdapter adapter;
    private List<BraceletData> lists;

    private RecyclerView recycler_view;
    private RecommendedDoctorAdapter rdadapter;
    private List<Doctor> doctors;


    private EditText search;
    private CustomTextSwitcher tvDownUpTextSwitcher;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        requestBasicPermission();
        authorityManage();

        //接口InformUpdateListener的实现方法，监听数据更新中是否有首页图片更新
        InformUpdateListenerManager informUpdateListenerManager = new InformUpdateListenerManager(this.getActivity());
        informUpdateListenerManager.getInstance(this.getActivity()).setInformUpdateListener(new MyInformUpdateListener(this.getActivity()));

        //走马灯
        tvDownUpTextSwitcher = view.findViewById(R.id.tvDownUpTextSwitcher);
        String[] data = new String[]{"腰椎间盘突出治疗方法选择", "聊聊ICL术后那些事", "早泄和阳痿合并的诊治", "怎么判断自己有没有心理疾病"};
        // 上下滚动
        tvDownUpTextSwitcher.setInAnimation(R.anim.animation_down_up_in_animation)
                .setOutAnimation(R.anim.animation_down_up_out_animation)
                .bindData(data)
                .startSwitch(2000L);


        LinearLayoutManager layout = new LinearLayoutManager(HomeFragment.this.getActivity());
        layout.setOrientation(LinearLayoutManager.HORIZONTAL);//设置为横向排列
        bracelet = view.findViewById(R.id.bracelet);
        bracelet.setLayoutManager(layout);
        adapter = new BraceletDataAdapter(HomeFragment.this.getActivity(), 1);
        bracelet.setAdapter(adapter);
        lists = new ArrayList<>();
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            protected void onItemClick(View view, int listPosition) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent(HomeFragment.this.getActivity(), PatientMessageDetailsActivity.class);
                    intent.putExtra("patient_id", lists.get(listPosition).getPatient_id()+"");
                    startActivity(intent);

                }

            }
        });

        laba = view.findViewById(R.id.laba);
        laba.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LiveActivity.class);
                    startActivity(intent);

                }
            }
        });

        l_More = view.findViewById(R.id.l_More);
        l_More.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), LiveActivity.class);
                startActivity(intent);
            }
        });

        recycler_view = view.findViewById(R.id.recycler_view);
        rdadapter = new RecommendedDoctorAdapter(this.getActivity());
        LinearLayoutManager layouta = new LinearLayoutManager(HomeFragment.this.getActivity());
        layouta.setOrientation(LinearLayoutManager.HORIZONTAL);//设置为横向排列
        recycler_view.setLayoutManager(layouta);
        recycler_view.setAdapter(rdadapter);
        rdadapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            protected void onItemClick(View view, int listPosition) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {


                    String did = doctors.get(listPosition).getMember_id() + "";
                    //目前Activity→目标Activity
                    Intent intent = new Intent(HomeFragment.this.getContext(), DoctorDetailsActivity.class);
                    intent.putExtra("doctor_id", did);
                    intent.putExtra("class_id", doctors.get(listPosition).getClass_id() + "");
                    intent.putExtra("hosp_id", doctors.get(listPosition).getHosp_id() + "");
                    startActivity(intent);


                }

            }
        });
        doctors = new ArrayList<>();

        more_doctor = view.findViewById(R.id.more_doctor);
        more_doctor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), FamousDoctorHallActivity.class);
                    startActivity(intent);

                }
            }
        });

//        image_fz = view.findViewById(R.id.image_fz);
//        image_fz.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                Intent intent = new Intent();
//                intent.setClass(HomeFragment.this.getContext(), ThePreventionActivity.class);
//                startActivity(intent);
//
//            }
//        });


        message_button = view.findViewById(R.id.message_button);
        mBadgeView  = new BadgeTextView(this.getContext());

        mBadgeView.setTargetView(message_button);//设置目标targetView(可任意:此处只做演示)
        mBadgeView.setBadgeCount(0)//数量(0:表示小红点)
                .setmDefaultRightPadding(10)//右依附视图距离
                .setmDefaultTopPadding(10);//上依附视图距离

        if (MyApplication.unread_message()) {

            mBadgeView.setVisibility(View.VISIBLE);

        }else{

            mBadgeView.setVisibility(View.GONE);
        }

        message_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {
                    mBadgeView.setVisibility(View.GONE);
                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), MessageActivity.class);
                    startActivity(intent);

                }
            }
        });

        zhibo = view.findViewById(R.id.zhibo);
        zhibo.setOnClickListener(v -> {

            Intent intent = new Intent();
            intent.setClass(HomeFragment.this.getContext(), LiveActivity.class);
            startActivity(intent);

        });
        zhibo1 = view.findViewById(R.id.zhibo1);
        zhibo1.setOnClickListener(v -> {

            Intent intent = new Intent();
            intent.setClass(HomeFragment.this.getContext(), LiveActivity.class);
            startActivity(intent);

        });

        relative_f = view.findViewById(R.id.relative_f);
        relative_f.setOnClickListener(v -> {

            Intent intent = new Intent();
            intent.setClass(HomeFragment.this.getContext(), ThePreventionActivity.class);
            startActivity(intent);

        });

        search = view.findViewById(R.id.search);
        search.setFocusable(false);
        search.setOnClickListener(v -> {

            Intent intent = new Intent();
            intent.setClass(HomeFragment.this.getContext(), DiseaseSearchActivity.class);
            startActivity(intent);

        });

        liLayout1 = view.findViewById(R.id.liLayout1);
        liLayout1.setFocusable(false);
        liLayout1.setOnClickListener(v -> {
            if (!MyApplication.isLogin_state()) {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                startActivityForResult(intent, 10);

            } else {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), HealthDetectionActivity.class);
                startActivity(intent);

            }

        });

        liLayout3 = view.findViewById(R.id.liLayout3);
        liLayout3.setFocusable(false);
        liLayout3.setOnClickListener(v -> {

            Intent intent = new Intent();
//            intent.setClass(HomeFragment.this.getContext(), IntelligentChatActivity.class);
            intent.setClass(HomeFragment.this.getContext(), UpdateIntelligentChatActivity.class);
            startActivity(intent);

        });
        liLayout2 = view.findViewById(R.id.liLayout2);
        liLayout2.setOnClickListener(v -> {

            if (!MyApplication.isLogin_state()) {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                startActivityForResult(intent, 10);

            } else {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), FamilyArchivesActivity.class);
                startActivity(intent);

            }

        });
        relative_a = view.findViewById(R.id.relative_a);
        relative_a.setOnClickListener(v -> {

            if (!MyApplication.isLogin_state()) {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                startActivityForResult(intent, 10);

            } else {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), AllDoctorActivity.class);
                startActivity(intent);
            }


        });
//        relative1 = view.findViewById(R.id.relative1);
//        relative1.setOnClickListener(v -> {
//
//            if (!MyApplication.isLogin_state()) {
//
//                Intent intent = new Intent();
//                intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
//                startActivityForResult(intent, 10);
//
//            } else {
//
//                Intent intent = new Intent();
//                intent.setClass(HomeFragment.this.getContext(), MakeAppointmentActivity.class);
//                startActivity(intent);
//
//            }
//        });

        relative2 = view.findViewById(R.id.relative2);
        relative2.setOnClickListener(v -> {

            if (!MyApplication.isLogin_state()) {

                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                startActivityForResult(intent, 10);

            } else {
                Intent intent = new Intent();
                intent.setClass(HomeFragment.this.getContext(), FamousDoctorHallActivity.class);
                startActivity(intent);
            }


        });

        relative3 = view.findViewById(R.id.relative3);
        relative3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {
                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), MallMedicineActivity.class);
                    startActivity(intent);
                }


            }
        });

        relative4 = view.findViewById(R.id.relative4);
        relative4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), TCMKnowledgeActivity.class);
                    startActivity(intent);

                }


            }
        });

        relative5 = view.findViewById(R.id.relative5);
        relative5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {
                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), CommunityActivity.class);
                    startActivity(intent);

                }


            }
        });


        relative6 = view.findViewById(R.id.relative6);
        relative6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), HealthActivity.class);
                    startActivity(intent);

                }


            }
        });


        relative7 = view.findViewById(R.id.relative7);
        relative7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {
                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), MedicinalFoodRecipesActivity.class);
                    startActivity(intent);

                }
            }
        });

        relative8 = view.findViewById(R.id.relative8);
        relative8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), COVIDActivity.class);
                    startActivity(intent);


                }
            }
        });


        relative9 = view.findViewById(R.id.relative9);
        relative9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), PatientsLocationActivity.class);
                    startActivity(intent);


                }
            }
        });
        relative10 = view.findViewById(R.id.relative10);
        relative10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyApplication.isLogin_state()) {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), LoginActivity.class);
                    startActivityForResult(intent, 10);

                } else {

                    Intent intent = new Intent();
                    intent.setClass(HomeFragment.this.getContext(), FamilyArchivesActivity.class);
                    startActivity(intent);

                }
            }
        });

//        adapter = new ArticleMessageAdapter(this.getActivity());
//        re_doctor = view.findViewById(R.id.re_doctor);
//        re_doctor.setLayoutManager(new LinearLayoutManager(this.getContext()));
//        re_doctor.setAdapter(adapter);
//        lists = new ArrayList<>();
//        adapter.setOnItemClickListener(new OnItemClickListener() {
//            @Override
//            protected void onItemClick(View view, int listPosition) {
//
//                //目前Activity→目标Activity
//                Intent intent = new Intent(HomeFragment.this.getContext(), ArticleDetailsActivity.class);
//                intent.putExtra("am", lists.get(listPosition));
//                startActivity(intent);
//
//            }
//        });
//        getAllDoctor();
        getAllDoctors();
        getInfo();
        return view;
    }


    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            switch (msg.what) {

                case 1:

//                    Log.e("ffffffffffff", msg.obj.toString());
//
//                    try {
//
//                        JSONObject object = new JSONObject(msg.obj.toString());
//                        JSONArray array = object.getJSONArray("data");
//
//                        Gson gson = new Gson();
//                        for (int i = 0; i < array.length(); i++) {
//
//                            JSONObject jsonObject = array.getJSONObject(i);
//                            ArticleMessage articleMessage = gson.fromJson(jsonObject.toString(), ArticleMessage.class);
//                            lists.add(articleMessage);
//                        }
//                        adapter.setListAndNotifyDataSetChanged(lists);
//
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }

                    break;
                case 2:

                    JSONObject jsonObject = null;
                    try {

                        jsonObject = new JSONObject(msg.obj.toString());
                        JSONArray array = jsonObject.getJSONArray("data");
                        Gson g = new Gson();
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject object = array.getJSONObject(i);
                            Doctor c = g.fromJson(object.toString(), Doctor.class);
                            doctors.add(c);

                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    rdadapter.setListAndNotifyDataSetChanged(doctors);//就是设置list然后刷新
                    break;

                case 3:

                    try {

                        lists.clear();
                        JSONObject object = new JSONObject(msg.obj.toString());

                        if (object.getInt("code") == 1) {


                            JSONArray array = object.getJSONArray("data");
                            Gson gson = new Gson();
                            for (int i = 0; i < array.length(); i++) {

                                BraceletData bd = gson.fromJson(array.getJSONObject(i).toString(), BraceletData.class);
                                lists.add(bd);

                            }

                            adapter.setListAndNotifyDataSetChanged(lists);//就是设置list然后刷新

                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    break;
            }

        }
    };

    @Override
    public void initImmersionBar() {
        ImmersionBar.with(this).titleBarMarginTop(R.id.toolbar).statusBarDarkFont(true).init();
    }

//    public void getAllDoctor() {
//
//        Map<String, Object> params = new HashMap<String, Object>();
//        params.put("data[row]", 1 + "");
//        params.put("data[number]", 10 + "");
//        params.put("data[client]", 1 + "");
//        params.put("cmd", "getAllArticle");
//        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/article/", params, handler, 1, 404);
//
//    }

    public void getAllDoctors() {

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("cmd", "getAllDoctor");
        params.put("data[row]", 1 + "");
        params.put("data[number]", 10 + "");
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/api/", params, handler, 2, 404);

    }

    /**
     * 权限申请
     */
    private void authorityManage() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            if (ContextCompat.checkSelfPermission(HomeFragment.this.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(HomeFragment.this.getActivity(),
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        1);
            }
        }
    }

    private static final int BASIC_PERMISSION_REQUEST_CODE = 100;

    private void requestBasicPermission() {

        MPermission.printMPermissionResult(true, HomeFragment.this.getActivity(), BASIC_PERMISSIONS);
        MPermission.with(HomeFragment.this)
                .setRequestCode(BASIC_PERMISSION_REQUEST_CODE)
                .permissions(BASIC_PERMISSIONS)
                .request();

    }


    /**
     * 基本权限管理
     */
    private final String[] BASIC_PERMISSIONS = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.RECORD_AUDIO,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION
    };


    //获取血压数据
    public void getInfo() {

        //请求网络
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sign", AllUtil.md5(sing(null)));
        params.put("token", MySharedPreferences.getInstance(this.getContext()).getString(MySharedPreferences.token, ""));
        params.put("uid", MySharedPreferences.getInstance(this.getContext()).getString(MySharedPreferences.uid, ""));
        params.put("ts", System.currentTimeMillis() / 1000); // 当前时间戳
        params.put("cmd", "getInfo");
        params.put("data[]", "");
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/watch/", params, handler, 3, 404);

    }

    //签名
    public String sing(List<String> list) {

        StringBuilder requestparams = new StringBuilder();
        requestparams.append(MySharedPreferences.getInstance(this.getContext()).getString(MySharedPreferences.uid, "") +
                MySharedPreferences.getInstance(this.getContext()).getString(MySharedPreferences.role, "") +
                System.currentTimeMillis() / 1000 + MySharedPreferences.getInstance(this.getContext()).getString(MySharedPreferences.password, ""));

        if (list != null) {
            for (String s : list) {
                requestparams.append(s);
            }
        }
        return requestparams.toString();

    }

    //静态内部类实现接口监听
    static class MyInformUpdateListener implements MessageUpdateListener {
        private WeakReference<Activity> mWeakReference;
        public MyInformUpdateListener(Activity activity){
            Log.e("有消息进来了1","有消息进来了1");
            mWeakReference = new WeakReference<Activity>(activity);//使用弱引用引用外部Activity对象
        }

        @Override
        public void updateMessage() {

            Log.e("有消息进来了","有消息进来了");
            mBadgeView.setVisibility(View.VISIBLE);

        }
    }

}